import logging
import grpc
import time
import test_pb2
import test_pb2_grpc


def send_stream():
    message_list = ['1', '2', '3', '4', '5', '6', '7', '8', '9']
    for i in message_list:
        time.sleep(1)
        yield test_pb2.request(message=i)


def run():
    with grpc.insecure_channel("localhost:10086") as channel:
        client = test_pb2_grpc.StreamTestStub(channel)
        response = client.BothStream(send_stream())
        for i in response:
            print("服务端返回：", i.message)


if __name__ == "__main__":
    logging.basicConfig()
    run()

